//
//  MyAddressSectionHeaderView.m
//  FD
//
//  Created by Yasin on 2018/10/17.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "MyAddressSectionHeaderView.h"
//h:44
@interface MyAddressSectionHeaderView()
/**bgView*/
@property (nonatomic, strong) UIView *bgView;

/**nameLb*/
@property (nonatomic,  strong) UILabel *nameLb;
/**新增按钮bnt*/
@property (nonatomic,  strong) UIButton *addBtn;
@end

@implementation MyAddressSectionHeaderView
//初始化方法写错了
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
        
        self.contentView.backgroundColor = kMainLightGrayColor;
    }
    return self;
}
- (void)setupView
{
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.nameLb];
    [self.bgView addSubview:self.addBtn];
}

- (void)layoutSubviews {
    [super layoutSubviews];

    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-1); //1px线
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(25);
        make.right.equalTo(self.addBtn.mas_left);
    }];
    
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 20));
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.right.equalTo(self.bgView.mas_right).offset(-10);
    }];
}

//getter
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        
        _nameLb.text = NSLocalizedString(DeliveryAddress, @"送餐地址");
        _nameLb.font = [UIFont systemFontOfSize:15*kScaleFit];
    }
    return _nameLb;
}
- (UIButton *)addBtn
{
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_addBtn setTitle:NSLocalizedString(AddNew, @"新增") forState:(UIControlStateNormal)];

        _addBtn.titleLabel.font = [UIFont systemFontOfSize:15*kScaleFit];
        [_addBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_addBtn setImage:[UIImage imageNamed:@"加"] forState:(UIControlStateNormal)];

        //不然拉伸，没屌用
        _addBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [_addBtn addTarget:self action:@selector(clickAddBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        _addBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; //右对齐 2019-2-16好使
    }
    return _addBtn;
}

- (void)clickAddBtnAction:(UIButton *)btn
{
    RBFunctionLog
    
    if (self.myAddressSectionHeaderViewClickAddBlock) {
        self.myAddressSectionHeaderViewClickAddBlock();
    }
}
@end

